//
//  DepositsAmountCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/5/17.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "DepositsAmountCell.h"

@interface DepositsAmountCell()<UITextFieldDelegate>

@property (nonatomic,strong) UIView *bgView;

@property (nonatomic,strong) UILabel *topTitleLB;
@property (nonatomic,strong) UILabel *leftLB;
@property (nonatomic,strong) UITextField *amount_TF;

@property (nonatomic,strong) UIView *lineV;
@property (nonatomic,strong) UILabel *balanceLB;//显示剩余余额

@property (nonatomic,strong) UIButton *allDeposBtn;//全部提现


@end

@implementation DepositsAmountCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = MainBackColor;
        self.backgroundColor = MainBackColor;
        
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setDeposDict:(NSMutableDictionary *)deposDict{
    _deposDict = deposDict;
    self.amount_TF = _deposDict[@"amount"];
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.topTitleLB];
    [self.bgView addSubview:self.leftLB];
    [self.bgView addSubview:self.amount_TF];
    [self.bgView addSubview:self.lineV];
    [self.bgView addSubview:self.balanceLB];
    [self.bgView addSubview:self.allDeposBtn];
}

#pragma mark - lazy
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}
- (UILabel *)topTitleLB{
    if (!_topTitleLB) {
        _topTitleLB = [[UILabel alloc] initWithFrame:CGRectMake(14, 25, 120, 20)];
        _topTitleLB.textColor = MainPureColor(102);
        _topTitleLB.textAlignment = NSTextAlignmentLeft;
        _topTitleLB.font = FontSet(15);
        _topTitleLB.text = @"提现金额";
    }
    return _topTitleLB;
}
- (UILabel *)leftLB{
    if (!_leftLB) {
        _leftLB = [[UILabel alloc] initWithFrame:CGRectMake(10, self.topTitleLB.bottom+15, 30, 37)];
        _leftLB.textColor = UIColor.blackColor;
        _leftLB.textAlignment = NSTextAlignmentRight;
        _leftLB.font = FontSetWithWeight(26, 0.4f);
        _leftLB.text = @"¥";
    }
    return _leftLB;
}
- (UITextField *)amount_TF{
    if (!_amount_TF) {
        _amount_TF = [[UITextField alloc] initWithFrame:CGRectMake(self.leftLB.right+5, self.leftLB.top-6, ScreenWidth-60, 50)];
        _amount_TF.textColor = UIColor.blackColor;
        _amount_TF.textAlignment = NSTextAlignmentLeft;
        _amount_TF.keyboardType = UIKeyboardTypeNumberPad;
        _amount_TF.font = FontSetWithWeight(36, 0.4f);
        _amount_TF.delegate = self;
    }
    return _amount_TF;
}
- (UIView *)lineV{
    if (!_lineV) {
        _lineV = [[UIView alloc] initWithFrame:CGRectMake(10, self.amount_TF.bottom+8, ScreenWidth-20, 1)];
        _lineV.backgroundColor = MainPureColor(239);
    }
    return _lineV;
}
- (UILabel *)balanceLB{
    if (!_balanceLB) {
        _balanceLB = [[UILabel alloc] initWithFrame:CGRectMake(10, self.lineV.bottom + 14, 160, 20)];
        _balanceLB.font = FontSet(14);
        _balanceLB.textAlignment = NSTextAlignmentLeft;
        _balanceLB.textColor = MainPureColor(102);
        _balanceLB.text = [NSString stringWithFormat:@"可提现 ¥%.02f",[UserInfomationManager shareManager].balance];
    }
    return _balanceLB;
}

- (UIButton *)allDeposBtn{
    if (!_allDeposBtn) {
        _allDeposBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _allDeposBtn.frame = CGRectMake(ScreenWidth - 80, self.balanceLB.top - 5, 70, 30);
        [_allDeposBtn.titleLabel setFont:FontSet(14)];
        [_allDeposBtn setTitle:@"全部提现" forState:normal];
        [_allDeposBtn setTitleColor:RGB(37, 130, 255) forState:normal];
        [_allDeposBtn addTarget:self action:@selector(allDeposClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _allDeposBtn;
}

//全部提现
-(void)allDeposClick{
//    float balance = [UserInfomationManager shareManager].balance;
////    balance = 0.02;
//    if (balance>0) {
//        [self.amount_TF setText:[NSString stringWithFormat:@"%.02f",balance]];
//    }else{
//        [self.amount_TF setText:@""];
//    }
//    self.deposDict[@"account"] = self.amount_TF.text;
//    if (self.updateDeposBlock) {
//        self.updateDeposBlock(self.deposDict);
//    }
}

#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField{
    if ([textField.text floatValue] > [UserInfomationManager shareManager].balance) {
        [[XNProgressHUD shared]showWithTitle:@"可提现余额不足"];
    }
    self.deposDict[@"amount"] = textField.text;
    if (self.updateDeposBlock) {
        self.updateDeposBlock(self.deposDict);
    }
}





@end





